//********************************************************************************************************
// Product Name: MapWindow.dll Alpha
// Description:  Low level interfaces that allow separate components to use objects that are defined
//               in completely independant libraries so long as they satisfy the basic interface requirements.
//********************************************************************************************************
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
// you may not use this file except in compliance with the License. You may obtain a copy of the License at 
// http://www.mozilla.org/MPL/ 
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 
// ANY KIND, either express or implied. See the License for the specificlanguage governing rights and 
// limitations under the License. 
//
// The Original Code is MapWindow.dll
//
// The Initial Developer of this Original Code is Ted Dunsford. Created in September, 2007.
// 
// Contributor(s): (Open source contributors should list themselves and their modifications here). 
//
//********************************************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using MapWindow.Main;
using MapWindow.Data;
using MapWindow.Geometries;

namespace MapWindow.Drawing
{
    /// <summary>
    /// A collection of Polygons with drawing characteristics
    /// </summary>
    public class MapPolygonCollection: EventList<IMapPolygon>
    {
        /// <summary>
        /// Creates a new instance of a MapPointCollection
        /// </summary>
        /// <param name="ParentLayer">The IMapPointLayer in question</param>
        public MapPolygonCollection(IMapPolygonLayer ParentLayer)
        {
            _List = new List<IMapPolygon>();
            if (ParentLayer == null) return;
            if (ParentLayer.Features == null) return;
            foreach (IFeature f in ParentLayer.Features)
            {
                MapPolygon mp = new MapPolygon(f, ParentLayer.PolygonSymbolizer);
                mp.ParentFeatureLayer = (IFeatureLayer)ParentLayer;
                mp.ParentMapPolygonLayer = ParentLayer; 
                _List.Add(mp);
            }

        }


        /// <summary>
        /// This is a constructor that will build the collection of empty map points
        /// from the features in the specified feature layer as long as those features are points.
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <exception cref="System.InvalidCastException">"The specified featureLayer returned a feature type other than Point"</exception>
        public MapPolygonCollection(IFeatureLayer featureLayer)
        {
            _List = new List<IMapPolygon>();
            
            if (featureLayer.FeatureType != FeatureTypes.Point)
            {
                throw new InvalidCastException("The specified featureLayer returned a feature type other than Point");
            }
            foreach(IFeature f in featureLayer.Features)
            {
                MapPolygon mp = new MapPolygon(f);
                mp.ParentFeatureLayer = featureLayer;
                _List.Add(mp);
            }
        }

        /// <summary>
        /// Creates a new, empty instance of the collection
        /// </summary>
        public MapPolygonCollection()
        {
            _List = new List<IMapPolygon>();
        }
    }
}
